package 文件io;
import java.util.*;
import java.io.*;
//aide测试不成功，大概了解写法，以后备用
/*
 Properties工具栏可读可写
 ResourceBundle只能读取
*/
class Properties工具类
{
	private static String version="";
	private static String name="";
	private static String password="";
	/*
	放在静态代码块，初始化时加载
	static{readconfig}
	*/
	//读取配置文件
	private static void readconfig(){
		Properties p=new Properties();
		try
		{
			//通过当前类加载器对象来加载指定包下的配置文件
			InputStream in=Thread.currentThread().getContextClassLoader().getResourceAsStream("/文件io/files/config.properties");
			//InputStream in=new FileInputStream("config.properties");//放在项目根目录可以直接写相对路径
			p.load(in);//加载文件
			//获取配置数据
			version=p.getProperty("version");
			name=p.getProperty("name");
			password=p.getProperty("password");
			in.close();
		}
		catch (IOException e)
		{}
	
	}
	//写配置文件
	private static void writeconfig(String version,String name,String password){
		Properties p=new Properties();
		p.put("version",version);
		p.put("name",name);
		p.put("password",password);
		
		try
		{
			Writer out = new FileWriter("config.properties");
			p.store(out, "写入配置");
		}
		catch (IOException e)
		{}
		
	}
	public static void main(String[]args){
		writeconfig("5","nihao","1234567");
		//readconfig();
		System.out.println(Properties工具类.version);
	}
	
}
